<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <!-- 头部操作栏 -->
            <form class="layui-form">
                <div class="layui-form lay-header">
                    <div class="toolbar">
                        <div class="layui-form-item lay-query-content">
                            <div class="lay-query-box">
                                <div class="query-lt">
                                    <div class="layui-inline">
                                        <label class="layui-form-label w-auto">工序：</label>
                                        <div class="layui-input-inline">
                                            <select name="processId" id="selectProcessId">
                                                <option value="">选择工序</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label">质检任务编号：</label>
                                        <div class="layui-input-inline">
                                            <input name="code" class="layui-input" type="text" placeholder="请输入质检任务编号"/>
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label">工单编号：</label>
                                        <div class="layui-input-inline">
                                            <input name="workOrderCode" class="layui-input" type="text" placeholder="请输入工单编号"/>
                                        </div>
                                    </div>
                                    <!--<div class="layui-inline">
                                        <label class="layui-form-label">送检人：</label>
                                        <div class="layui-input-inline">
                                            <input name="" class="layui-input" type="text" placeholder="请输入送检人"/>
                                        </div>
                                    </div>-->
                                    <div class="layui-inline">
                                        <label class="layui-form-label">状态：</label>
                                        <div class="layui-input-inline">
                                            <select name="">
                                                <option value="">请选择</option>
                                                <option value="inspect">送检中</option>
                                                <option value="finish">完成</option>
                                                <option value="confirm">待认领</option>
                                                <option value="close">关闭</option>
                                            </select>
                                        </div>
                                    </div>
                                </div>
                                <div class="query-rt">
                                    <div class="layui-inline">
                                        <button type="button" class="layui-btn icon-btn color-green"
                                                lay-filter="formSubSearchLog" lay-submit>查询
                                        </button>
                                        <button class="layui-btn icon-btn color-white" lay-filter="resets" lay-submit
                                                type="button">
                                            重置
                                        </button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="lay-btn-rows">
                        <div class="lay-btn-box">
                            <div class="lay-btn-lt">
                                <button id="workOrderQualityTestingTaskBtnAdd" class="layui-btn icon-btn color-reseda"
                                        type="button">
                                    添加质检任务
                                </button>
                            </div>
                            <div class="lay-btn-rt">
                            </div>
                        </div>
                    </div>
                </div>
            </form>
            <!-- 表格 -->
            <table class="layui-table" id="workOrderQualityTestingTaskTable"
                   lay-filter="workOrderQualityTestingTaskTable"></table>
        </div>
    </div>
</div>

<style>
    div[lay-id="addQualityInspectionTaskTable"] .layui-form,
    div[lay-id="addQualityInspectionTaskTable"] .layui-table-box,
    div[lay-id="addQualityInspectionTaskTable"] .layui-table-body {
        overflow: visible;
    }
    div[lay-id="addQualityInspectionTaskTable"] .layui-table-cell {
        padding: 10px;
        height: auto;
    }
</style>

<!-- 表格操作列 -->
<script type="text/html" id="workOrderQualityTestingTaskTableBar">
      {{# if(d.whetherEdit=="0" && d.status=="inspect"){  }}
          <a class="layui-btn layui-btn-xs" lay-event="details">详情</a>
          <a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="print">打印</a>
          <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="close">关闭</a>
      {{# }else if(d.whetherEdit=="0" && d.status=="finish"){ }}
          <a class="layui-btn layui-btn-xs" lay-event="details">详情</a>
          <a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="print">打印</a>
      {{# }else if(d.whetherEdit=="0" && d.status=="confirm"){ }}
          <a class="layui-btn layui-btn-xs" lay-event="details">详情</a>
          <a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="print">打印</a>
          <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="close">关闭</a>
          <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">修改</a>
          <a class="layui-btn layui-btn-xs" lay-event="determine">确定</a>
      {{# }else if(d.whetherEdit=="0" && d.status=="close"){ }}

      {{# } }}
</script>

<!--{{#  if(d.status=="inspect"){ }}
   <a class="layui-btn layui-btn-xs" lay-event="details">详情</a>
   <a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="print">打印</a>
   <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="close">关闭</a>
   {{# }else if(d.status=="finish") { }}
   <a class="layui-btn layui-btn-xs" lay-event="details">详情</a>
   <a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="print">打印</a>
   {{# }else if(d.status=="confirm") { }}
   <a class="layui-btn layui-btn-xs" lay-event="details">详情</a>
   <a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="print">打印</a>
   <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="close">关闭</a>
   {{# }else if(d.status=="close") { }}

   {{# } }}-->

<!--  {{# if(d.whetherEdit=="0"){  }}
      <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">修改</a>
      <a class="layui-btn layui-btn-xs" lay-event="determine">确定</a>
  {{# }else{ }}


  {{# } }}-->

<!-- if(d.status=="finish"){ }}
 <a class="layui-btn layui-btn-xs" lay-event="details">详情</a>
 <a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="print">打印</a>
 <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="close">关闭</a>
 {{# }else if(d.status=="finish") { }}
 {{# } }}-->

<!--addQualityInspectionTask-->
<!--添加质检任务弹窗-->
<script id="addQualityInspectionTaskTemplate" type="text/html">
    <form lay-filter="addQualityInspectionTaskForm"
          class="layui-form model-form form-scroll">
        <div class="open-details-box pd-20">
            <input name="id" type="hidden"/>
            <div class="layui-form-item" style="margin: 20px 0;" id="productionPlanIdBox">
                <label class="layui-form-label w-auto">选择开工单：</label>
                <div class="layui-input-inline">
                    <input name="productionPlanId" id="productionPlanId" class="layui-input" type="text"
                           placeholder="请选择开工单" readonly="readonly" style="cursor: pointer;"/>
                </div>
            </div>
            <div class="layui-form-item" id="addQualityInspectionTaskTableBox" style="display: none;">
                <div class="open-details-title">开工单信息</div>
                <!-- 表格 -->
                <table class="layui-table" id="addQualityInspectionTaskTable"
                       lay-filter="addQualityInspectionTaskTable" style="margin: 1px 0 10px;"></table>
            </div>
            <div class="layui-form-item" id="addQualityInspectionTaskRemarkBox" style="display: none;">
                <label class="layui-form-label w-auto">送检备注说明：</label>
                <div class="layui-input-block" style="margin-left: 130px">
                    <textarea placeholder="送检备注说明" name="remark"
                              style="resize: none; padding: 10px;width: 100%;min-height: 80px;box-sizing: border-box"></textarea>
                </div>
            </div>
        </div>
        <div class="layui-form-item text-right pd-20">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
            <button class="layui-btn" lay-filter="addQualityInspectionTaskSubmit" lay-submit style="display: none;">提交
            </button>
        </div>
    </form>
</script>

<script type="text/html" id="addQualityInspectionTaskTableBar">
    <a class="layui-btn  layui-btn-xs" lay-event="print">打印标签</a>
</script>

<!--选择开工单-->
<script type="text/html" id="selectTheWorkProcessTemplate">
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-card-body">
                <!-- 头部操作栏 -->
                <div class="layui-form toolbar">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label w-auto">开工单编号：</label>
                            <div class="layui-input-inline mr0" style="width: 240px;">
                                <input name="code" class="layui-input" type="text" placeholder="开工单编号"/>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button class="layui-btn icon-btn" lay-filter="selectTheWorkProcessFormSubSearchLog"
                                    lay-submit style="padding: 0 24px;">
                                搜索
                            </button>
                            <button id="selectTheWorkProcessClose" class="layui-btn icon-btn">确认选择</button>
                        </div>
                    </div>
                </div>
                <!-- 表格 -->
                <table class="layui-table" id="selectTheWorkProcessTable"
                       lay-filter="selectTheWorkProcessTable"></table>
            </div>
        </div>
    </div>
</script>


<!-- js部分 -->
<script>
    layui.use(['layer', 'form', 'table', 'admin'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var config = layui.config;
        var admin = layui.admin;
        var upload = layui.upload;

        form.render('select');

        // 渲染表格
        var insTb = table.render({
            elem: '#workOrderQualityTestingTaskTable',
            url: config.base + 'production/qualityTesting/admin/workOrderQualityTestingTask/list',
            toolbar: true,
            defaultToolbar: ["filter"],
            page: true,
            cellMinWidth: 100,
            cols: [[
                {type: 'numbers', title: '序号'}
                , {field: 'code', title: '质检任务单编码'}
                , {field: 'processName', title: '所属工序'}
                , {field: 'testingCategoryName', title: '质检分类'}
                , {field: 'testingTypeName', title: '质检类型'}
                , {field: 'workOrderCode', title: '所属开工单'}
                , {field: 'deviceCode', title: '送检工站'}
                , {field: 'skuCode', title: '物料编码'}
                , {field: 'creatorName', title: '送检人'}
                , {field: 'createTime', title: '送检时间'}
                , {field: 'submissionQuantity', title: '送检数量'}
                , {field: 'statusDesc', title: '状态'}
                , {field: 'inspectDeviceCode', title: '检验工站'}
                , {field: 'inspector', title: '检验员'}
                , {field: 'inspectTime', title: '检出时间'}
                , {align: 'center', toolbar: '#workOrderQualityTestingTaskTableBar', title: '操作', width: 290,fixed: 'right'}
            ]],
            done: function (res, curr, count) {
                //移除按钮
            }
        });
// 工序名称
        admin.req('enterprise/product/admin/processInfo/getAllProcessInfo', {}, function (res) {
            if (res.code == 200) {
                $.each(res.data, function (index, item) {
                    $("#selectProcessId").append(new Option(item.nodeNames, item.id));
                });
                form.render('select');
            } else {
                layer.msg(res.msg, {icon: 2});
            }
        }, 'GET');
        // 工具条点击事件
        table.on('tool(workOrderQualityTestingTaskTable)', function (obj) {
            let data = obj.data;
            if (obj.event === 'edit') { //修改
                showQualityInspectionTaskModel(data, 'edit')
            } else if (obj.event === 'del') { // 删除
                doDelete(obj);
            } else if (obj.event === 'details') {
                showQualityInspectionTaskModel(data, 'details')
            } else if (obj.event === 'print') {
                doPrint(obj)
            } else if (obj.event === 'close') {
                doClose(data)
            } else if (obj.event === 'determine') {
                showQualityInspectionTaskModel(data, 'determine');
            }
        });

        //监听排序
        table.on('sort(workOrderQualityTestingTaskTable)', function (obj) {
            table.reload('workOrderQualityTestingTaskTable', {
                initSort: obj
                , where: {
                    sort: obj.field
                    , order: obj.type
                }
            });
        });

        // 搜索
        form.on('submit(formSubSearchLog)', function (data) {
            insTb.reload({where: data.field, page: {curr: 1}}, 'data');
        });

        // 重置搜索
        form.on('submit(resets)', function (data) {
            $(".lay-header").find('select').val("");
            $(".lay-header").find('input').val("");
            var field = data.field;
            for (let key in field) {
                field[key] = ''
            }
            insTb.reload({where: field, page: {curr: 1}}, 'data');
            return false;
        });


        // 添加按钮点击事件
        $('#workOrderQualityTestingTaskBtnAdd').click(function () {
            showQualityInspectionTaskModel();
        });

        let addQualityInspectionTaskTableData = [];

        // 添加质检任务弹窗 && 质检任务详情弹窗
        function showQualityInspectionTaskModel(data, _type) {
            admin.open({
                type: 1,
                area: ['82%', '840px'],
                offset: '65px',
                title: data ? (_type === 'details' ? '送检任务详情' : '修改质检任务') : '添加质检任务',
                content: $('#addQualityInspectionTaskTemplate').html(),
                success: function () {
                    addQualityInspectionTaskTableData = [];
                    if (data) {
                        addQualityInspectionTaskTableData[0] = data;
                        $('form[lay-filter="addQualityInspectionTaskForm"] input[name="id"]').val(addQualityInspectionTaskTableData[0].id);
                        $('form[lay-filter="addQualityInspectionTaskForm"] textarea[name="remark"]').val(addQualityInspectionTaskTableData[0].remark);

                        if (_type == 'details') {
                            $('#productionPlanIdBox').hide();
                            $('form[lay-filter="addQualityInspectionTaskForm"] .open-details-title').css('margin', '20px 0 0 0');
                            $('button[lay-filter="addQualityInspectionTaskSubmit"]').hide();
                            $('form[lay-filter="addQualityInspectionTaskForm"] textarea[name="remark"]').attr('disabled', 'disabled');
                            $('form[lay-filter="addQualityInspectionTaskForm"] textarea[name="remark"]').css('border', "none");

                        } else {
                            $('#productionPlanId').val(data.workOrderCode);
                            getWorkOrderDetails(data.workOrderId, 'edit');
                        }
                    } else {
                        $('#productionPlanIdBox').show();
                        $('#productionPlanId').click(function () {
                            showSelectTheWorkProcessTemplateModel()
                        });
                    }

                    // 渲染表格
                    let addQualityInspectionTaskTb = table.render({
                        elem: '#addQualityInspectionTaskTable',
                        data: addQualityInspectionTaskTableData,
                        page: false,
                        cellMinWidth: 100,
                        cols: [[
                            {field: 'processName', title: '排产工序'}
                            , {field: 'deviceCode', title: '所属设备'}
                            , {field: 'planCode', title: '所属生产计划'}
                            , {field: 'productTypeName', title: '物料类型'}
                            , {field: 'skuCode', title: '物料编号'}
                            , {field: 'skuName', title: '物料名称'}
                            , {field: 'skuSpec', title: '规格码'}
                            , {
                                field: 'accessory', title: '附件',
                                templet: d => {
                                    if (d.accessory) {
                                        return '<a href="' + d.accessory + '" target="_blank" class="layui-btn layui-btn-warm layui-btn-xs">查看附件</a>'
                                    } else {
                                        return ''
                                    }
                                }
                            }
                            , {field: 'unitName', title: '单位'}
                            , {
                                field: 'qualityTestingCategoryId', title: '检验工单分类', width: '150',
                                templet: d => {
                                    let selectHTML = '';
                                    if (_type && _type === 'details') {
                                        selectHTML += d.testingCategoryName;
                                    } else {
                                        selectHTML += '<select name="qualityTestingCategoryId" lay-filter="qualityTestingCategoryId" lay-verify="required">';
                                        selectHTML += '<option value="">检验工单分类</option>';
                                        d.qualityTestingCategoryIdData.forEach(item => {
                                            if (item.id == d.qualityTestingCategoryId) {
                                                selectHTML += '<option value="' + item.id + '" selected="">' + item.name + '</option>';
                                            } else {
                                                selectHTML += '<option value="' + item.id + '">' + item.name + '</option>';
                                            }
                                        });
                                        selectHTML += '</select>';
                                    }
                                    return selectHTML
                                }
                            }
                            , {
                                field: 'qualityTestingTypeId', title: '送检类型', width: '150',
                                templet: d => {
                                    let selectHTML = '';
                                    if (_type && _type === 'details') {
                                        selectHTML += d.testingTypeName;
                                    } else {
                                        selectHTML += '<select name="qualityTestingTypeId" lay-filter="qualityTestingTypeId" lay-verify="required">';
                                        selectHTML += '<option value="">送检类型</option>';
                                        d.qualityTestingTypeIdData.forEach(item => {
                                            if (item.id == d.qualityTestingTypeId) {
                                                selectHTML += '<option value="' + item.id + '" selected="">' + item.name + '</option>';

                                            } else {
                                                selectHTML += '<option value="' + item.id + '">' + item.name + '</option>';
                                            }
                                        });
                                        selectHTML += '</select>';
                                    }
                                    return selectHTML
                                }
                            }
                            , {
                                field: 'submissionQuantity', title: '送检数量', width: '150',
                                templet: d => {
                                    if (_type && _type === 'details') {
                                        return d.submissionQuantity;
                                    } else {
                                        if (d.submissionQuantity) {
                                            return '<input  class="layui-input " lay-verify="number" name="submissionQuantity" value="' + d.submissionQuantity + '"/>';
                                        } else {
                                            return '<input  class="layui-input " lay-verify="number" name="submissionQuantity"/>';

                                        }
                                    }
                                }
                            }, _type == 'details' ? {
                                align: 'left',
                                toolbar: '#addQualityInspectionTaskTableBar',
                                title: '操作'
                            } : void 1

                        ]],
                        done: function (res, curr, count) {
                            $("td[data-field='qualityTestingCategoryId'] .layui-table-cell").css("overflow", 'visible');
                            $("td[data-field='qualityTestingTypeId'] .layui-table-cell").css("overflow", 'visible');
                            if (addQualityInspectionTaskTableData.length == 0) {
                                $('#addQualityInspectionTaskTableBox').hide();
                                $('#addQualityInspectionTaskRemarkBox').hide({duration: 300});
                                $('button[lay-filter="addQualityInspectionTaskSubmit"]').hide({duration: 300});

                            } else {
                                $('#addQualityInspectionTaskTableBox').show();
                                $('#addQualityInspectionTaskRemarkBox').show({duration: 300});
                                if (_type == 'details') {
                                    $('button[lay-filter="addQualityInspectionTaskSubmit"]').hide({duration: 300});
                                } else {
                                    $('button[lay-filter="addQualityInspectionTaskSubmit"]').show({duration: 300});
                                }
                            }
                        }
                    });

                    table.on('tool(addQualityInspectionTaskTable)', function (obj) {
                        let data = obj.data;
                        if (obj.event === 'print') { // 打印
                            doPrint(obj)
                        }
                    });

                    // 表单提交事件
                    form.on('submit(addQualityInspectionTaskSubmit)', function (d) {
                        delete d.field.productionPlanId;
                        if (data) {
                            d.field.id = addQualityInspectionTaskTableData[0].id;
                        } else {
                            d.field.workOrderId = addQualityInspectionTaskTableData[0].id;
                        }
                        if (_type === 'determine') {
                            d.field.status = 'inspect';
                        }
                        layer.load(2);
                        admin.req(data ? 'production/qualityTesting/admin/workOrderQualityTestingTask/update' : 'production/qualityTesting/admin/workOrderQualityTestingTask/add', d.field, function (res) {
                            layer.closeAll('loading');
                            if (res.code == 200) {
                                layer.msg(res.msg, {icon: 1});
                                table.reload('workOrderQualityTestingTaskTable');
                                layer.closeAll('page');
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, data ? 'PUT' : 'POST');
                        return false;
                    });
                }
            });
        }


        function showSelectTheWorkProcessTemplateModel() {
            let selectTheWorkProcessTemplate = admin.open({
                type: 1,
                title: '选择开工单',
                area: '75%',
                offset: '120px',
                content: $('#selectTheWorkProcessTemplate').html(),
                success: function () {
                    form.render("select");
                    // 渲染表格
                    let selectTheWorkProcessTable = table.render({
                        elem: '#selectTheWorkProcessTable',
                        url: config.base + 'production/productionPlan/admin/productionWorkOrder/list',
                        page: true,
                        cellMinWidth: 100,
                        cols: [[
                            {type: 'radio'}
                            , {field: 'code', title: '工单编码'}
                            , {field: 'processName', title: '所属工序'}
                            , {field: 'planCode', title: '所属生产计划'}
                            , {field: 'workOrderQualityDesc', title: '工单性质'}
                            , {field: 'deviceCode', title: '责任工站'}
                            , {field: 'skuCode', title: '物料编码(料号)'}
                            , {field: 'productionQuantity', title: '排产数量'}
                            , {field: 'finishQuantity', title: '已经完成'}
                            , {field: 'predictStartTime', title: '预计开始时间'}
                            , {field: 'predictFinishTime', title: '预计完工时间'}
                            , {field: 'statusDesc', title: '状态'}
                        ]],
                    });

                    // 搜索
                    form.on('submit(selectTheWorkProcessFormSubSearchLog)', function (data) {
                        selectTheWorkProcessTable.reload({
                            where: data.field,
                            page: {curr: 1}
                        }, 'data');
                    });

                    // 确认选择
                    $('#selectTheWorkProcessClose').click(function () {
                        let checkStatus = table.checkStatus('selectTheWorkProcessTable'); //test即为基础参数id对应的值
                        let dataS = checkStatus.data[0];
                        if (checkStatus.data.length == 0) {
                            layer.msg("请选择开工单", {icon: 2, time: 1000});
                        } else {
                            getWorkOrderDetails(dataS.id);
                            $("#productionPlanId").val(dataS.code);
                            layer.close(selectTheWorkProcessTemplate);
                        }
                    });
                }
            })
        }

        // 获取开工单信息和工序信息
        function getWorkOrderDetails(id, _type) {
            // addQualityInspectionTaskTableData
            let dataS = [];
            // 查询开工单信息
            admin.reqSync('production/qualityTesting/admin/workOrderQualityTestingTask/getWorkOrderInfoById', {workOrderId: id},
                res => {
                    if (res.code == 200) {
                        dataS = res.data;
                    }
                }, 'GET');
            // 查询所有质量参数分类（检验工单分类）
            admin.reqSync('production/qualityTesting/admin/processQualityCategory/list', {productTypeId: dataS.productTypeId},
                res => {
                    if (res.code == 200) {
                        dataS.qualityTestingCategoryIdData = res.data;
                    }
                }, 'GET');
            //查询所有质检类型
            admin.reqSync('production/qualityTesting/admin/qualityTestingType/list',
                {businessProperty: 1, status: 'enable'},
                res => {
                    if (res.code == 200) {
                        dataS.qualityTestingTypeIdData = res.data;
                    }
                }, 'GET');
            if (_type == 'edit') {
                addQualityInspectionTaskTableData[0] = Object.assign(dataS, addQualityInspectionTaskTableData[0]);
            } else {
                addQualityInspectionTaskTableData[0] = dataS;
            }
            table.reload('addQualityInspectionTaskTable', {
                data: addQualityInspectionTaskTableData,
            });
        }

        // 删除
        function doDelete(obj) {
            layer.confirm('确定要删除吗？', {
                offset: '65px',
                skin: 'layui-layer-admin'
            }, function (i) {
                layer.close(i);
                layer.load(2);
                admin.req('production/qualityTesting/admin/workOrderQualityTestingTask/' + obj.data.id, {}, function (res) {
                    layer.closeAll('loading');
                    if (res.code == 200) {
                        layer.msg(res.msg, {icon: 1});
                        obj.del();
                    } else {
                        layer.msg(res.msg, {icon: 2});
                    }
                }, 'DELETE');
            });
        }

        function jsToFormData(config) {
            const formData = new FormData();
            Object.keys(config).forEach((key) => {
                formData.append(key, config[key]);
            });

            return formData;
        }

        // console.log(jsToFormData({id: 11, status: 'close'}).getAll())

        // 关闭工单
        function doClose(data) {
            layer.confirm('确定要关闭吗？', {
                offset: '65px',
                skin: 'layui-layer-admin'
            }, function (i) {
                layer.close(i);
                layer.load(2);
                admin.req('production/qualityTesting/admin/workOrderQualityTestingTask/update',{id: data.id, status: 'close'}, function (res) {
                    layer.closeAll('loading');
                    if (res.code == 200) {
                        layer.msg(res.msg, {icon: 1});
                        table.reload('workOrderQualityTestingTaskTable');
                    } else {
                        layer.msg(res.msg, {icon: 2});
                    }
                }, 'put');
            });
        }

        // 导出excel
        $('#workOrderQualityTestingTaskBtnExport').click(function () {
            var checkRows = table.checkStatus('workOrderQualityTestingTaskTable');
            if (checkRows.data.length == 0) {
                layer.msg('请选择要导出的数据', {icon: 2});
            } else {
                table.exportFile(insTb.config.id, checkRows.data, 'xls');
            }
        });

        // 打印
        function doPrint(obj) {
            layer.confirm('确定要打印吗？', {
                offset: '65px',
                skin: 'layui-layer-admin'
            }, function (i) {
                layer.close(i);
                layer.load(2);
                admin.req('production/qualityTesting/admin/workOrderQualityTestingTask/printLabels', {id: obj.data.id}, function (res) {
                    layer.closeAll('loading');
                    if (res.code == 200) {
                        layer.msg(res.msg, {icon: 1});
                    } else {
                        layer.msg(res.msg, {icon: 2});
                    }
                }, 'get');
            });
        }
    });
</script>